import java.util.ArrayList;
import java.util.List;

/**
 * 原型设计模式：通过拷贝的方式来创建新的对象，一共分为浅拷贝、深拷贝，拷贝对象时不会执行构造函数
 *
 * @author ItJianGe
 * @data 2024/7/30 22:18
 */
public class PrototypeClone2 implements Cloneable {

    private String name;

    private List<String> nameList = List.of("yi", "er", "san");

    public PrototypeClone2(String name) {
        this.name = name;
        System.out.println("执行了构造函数。。。");
    }

    @Override
    protected PrototypeClone2 clone() {
        PrototypeClone2 prototypeClone2 = null;
        try {
            prototypeClone2 = (PrototypeClone2) super.clone();
            prototypeClone2.setNameList(this.nameList);
            return prototypeClone2;
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }

    public String getName() {
        return name;
    }

    public List<String> getNameList() {
        return nameList;
    }

    public void setNameList(List<String> nameList) {
        this.nameList = nameList;
    }
}
